# 注册 登录案例以及参数化
import pymysql

# xiaocui的修改
class User():

    def register(self,username,password):
        conn = pymysql.connections.Connection(host="127.0.0.1",port=3306,user="root",passwd="root",charset="utf8",db="test2")
        cursor = conn.cursor()
        # 提交sql
        # sql = "insert into user(username,password) values('{}','{}')".format(username,password)
        # d = cursor.execute(sql)
        # print(d)
        sql = "insert into user(username,password) values(%s,%s)" # 参数化 使用%s进行占位
        d = cursor.execute(sql,(username,password)) # 执行sql的 时候要进行替换的值 封装为一个元组传参执行
        conn.commit()
        cursor.close()
        conn.close()
        # 判断是否注册成功
        if d > 0:
            return {"status":200,"msg":"注册成功"}
        else:
            return {"status":400,"msg":"注册失败"}






# if __name__ == '__main__':
